#coding=utf-8
import unittest
from selenium import webdriver
from appium import webdriver
from time import sleep
from nav_plugin_op import nav_plugin_factory
from selenium.common.exceptions import WebDriverException
import os
from Public import BasePage
from Tool.usefulTools import userfulToolsFactory
from Public.BasePage import element_Oprate
from Public.BasePage import BasicAction
from Public import BaseConstant
import settings

#实例化基础数据
navOpenFactory = nav_plugin_factory()
userfulTool = userfulToolsFactory()
element_oprate_instance = element_Oprate()
element_find_instance = BasicAction()
Announcement_Paramter_instances = BaseConstant.Announcement_Paramter
# nav_name = "工作"
# plugin_name = "公文通告"		
nav_name = ["导航栏工作-公文通告",'xpath',"//android.widget.LinearLayout/android.widget.LinearLayout[2]/android.widget.FrameLayout/android.widget.RadioButton"]
plugin_name = ["插件列表-公文通告",'name','公文通告']		

class doc_announcement_factory():

	def open_announcement_plug(self,driver,file_path):
		try:
			sleep(5)
			# 点击工作的导航，打开工作列表
			element_oprate_instance.element_click(nav_name,file_path)
			# 点击"通用查询"的插件，打开插件
			element_oprate_instance.element_click(plugin_name,file_path)
			#等待通用查询页面内容进行加载，加载完成之后进行页面确认并界面
			element_oprate_instance.element_save_pic(file_path, 'open_announcement_plug_successful')

		except WebDriverException,error:
			print error
			element_oprate_instance.element_save_pic(file_path, 'open_announcement_plug_fail')
			raise

	def scan_file(self,driver,file_path):
		try:
			# 获取到 公文通告 第一条的标题
			Bulletin_title_list = element_find_instance.find_element(Announcement_Paramter_instances.Bulletin_first_title,settings.pic_file_path).get_attribute('text')
			element_oprate_instance.element_click(Announcement_Paramter_instances.Bulletin_first_title,settings.pic_file_path)
			sleep(5)
			Bulletin_title_detail = element_find_instance.find_element(Announcement_Paramter_instances.Bulletin_first_title,settings.pic_file_path).get_attribute('text')
			if Bulletin_title_list == Bulletin_title_detail:
				print u'公文通告--内容打开成功'
				element_oprate_instance.element_save_pic(file_path, 'scan_tips_successful')
			else:
				print u'公文通告内容打开失败'
				element_oprate_instance.element_save_pic(file_path, 'scan_tips_failed')
				raise

		except WebDriverException,error:
			print error
			element_oprate_instance.element_save_pic(file_path, 'scan_file_fail')
			raise


if __name__ == '__main__':
	unittest.main()	